<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>计算器</title>
</head>
<body>
<h1>计算器</h1>
<p>整数1：<input type="text" id="shu1"></p>
<p>整数2：<input type="text" id="shu2"></p>
<button onclick="change('p')">相加</button>
<button onclick="change('p1')">相减</button>
<button onclick="change('p2')">相乘</button>
<button onclick="change('p3')">相除</button>
<p>结果：<input type="text" id="shu3"></p>


<script>
    function change(e){
        var text = document.querySelector("#shu1").value;
        text = Number(text);
        var text1 = document.querySelector("#shu2").value;
        text1 = Number(text1);
        var res = 0;
        switch(e){
            case 'p':
                res = text + text1;
                break;
            case 'p1':
                res = text - text1;
                break;
            case 'p2':
                res = text * text1;
                break;
            case 'p3':
                res = text / text1;
            }
        document.querySelector("#shu3").value = res;
    }



</script>


</body>
</html>